package com.alison.SmartCli;

import java.util.HashMap;
import java.util.Map;

public class DefaultBeanFactory implements BeanFactory{

    Map<String,Object> BeanMap = new HashMap<>();

    @Override
    public Object getBean(Class clazz){
        String className = clazz.getName();
        if (BeanMap.containsKey(className)){
            return BeanMap.get(className);
        }else{
            try {
                Object target = clazz.newInstance();
                BeanMap.put(className,target);
                return target;
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
                throw new RuntimeException("无法加载"+className);
            }
        }
    }
}
